package selcoursesys.service.impl;

import selcoursesys.dao.UserDAO;
import selcoursesys.dao.impl.UserDAOImpl;
import selcoursesys.entity.UserEntity;
import selcoursesys.service.UserService;

import javax.jws.soap.SOAPBinding;
import java.util.List;

/**
 * Created by zzh on 2017/3/29.
 */
public class UserServiceImpl implements UserService{

    public List<UserEntity> checkUser(UserEntity user){
        UserDAO userdao=new UserDAOImpl();
        return userdao.checkUser(user);
    }

    @Override
    public boolean userLogin(UserEntity userEntity) {
        UserDAO userDAO=new UserDAOImpl();
        UserEntity userEntity1=userDAO.userLogin(userEntity);
        switch (userEntity.getUtype()){
            case "学生":
                userEntity.setUtype("stu");
                break;
            case "教师":
                userEntity.setUtype("tea");
                break;
            case "管理员":
                userEntity.setUtype("admin");
        }
        System.out.println(userEntity.getUid()+" "+userEntity.getUtype()+" "+userEntity.getUpwd());
        System.out.println(userEntity1.getUid()+" "+userEntity1.getUtype()+" "+userEntity1.getUpwd());
        if(userEntity.getUpwd().equals(userEntity1.getUpwd())==false||userEntity.getUid().equals(userEntity1.getUid())==false||userEntity.getUtype().equals(userEntity1.getUtype())==false){
            return false;
        }
        if(userEntity.getUpwd().equals(userEntity1.getUpwd())&&userEntity.getUid().equals(userEntity1.getUid())&&userEntity.getUtype().equals(userEntity1.getUtype())){
            return true;
        }
        if(userEntity1==null){
            return false;
        }
        return false;
    }
}
